<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();


if($_RQ['op']=='list'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_weishop_printer_template',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	
	$htmls=array(
			'type'=>'list',
			'tabs'=>array(
				array('op'=>'list','title'=>'打印模板管理'),
				array('op'=>'edit','title'=>'添加模板'),
			),
			'list'=>array('data'=>'list','list'=>array(
				array('name'=>'title','title'=>'模板名称','type'=>'string'),
				
				
			),
			),
		);
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='edit'){
	$return['datademo']=array(array('value'=>'','textstytle'=>'0'));	
	if($_RQ['id']){
		$item=pdo_get('jy_weishop_printer_template',array('id'=>$_RQ['id']));		
		$item['print_data']=json_decode($item['print_data'],true);
		$item['print_data']=$item['print_data'][0]['value']?$item['print_data']:$return['datademo'];
	}else{
		$item=array('print_data'=>$return['datademo']);
	}
	
	$return['item']=$item;	
	exi($return);
	}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array_fields(array('title','iscode','qrcode','isqrcode','print_style','print_top','goodssn','print_data'),$postdata);
	
	$data['print_data']=ijson_encode($data['print_data']);
	
	$id=intval($postdata['id']);
			if($id){
				pdo_update('jy_weishop_printer_template',$data,array('id'=>$id));
				exi('设置成功！','','list');
			}else{
			    $data['uniacid']=$_SESSION['uniacid'];
				 
				pdo_insert('jy_weishop_printer_template',$data);
				exi('添加成功！','','list');
			}
			}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_weishop_printer_template',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_weishop_printer_template',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>